fix(iOS): omit state when additionalParameters.state is null - #1125
Open
shashank-bhatotia wants to merge 1 commit into
Open
fix(iOS): omit state when additionalParameters.state is null#1125shashank-bhatotia wants to merge 1 commit into
shashank-bhatotia wants to merge 1 commit into
Conversation
|
@shashank-bhatotia is attempting to deploy a commit to the Nearform Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 04ab6b2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On iOS, passing
state: nullinadditionalParametersbuilds an authorization request whosestate is
NSNull. AppAuth then rejects the response:<null>isNSNull's description and(null)isnil's, so the message shows the requestcarried
NSNullwhile the response carried nothing.The cause is in
ios/RNAppAuth.m:JS
nullbridges toNSNull.NSNullis a real object and therefore truthy, so the ternarytakes the left branch and assigns it as the state.
Android already handles this.
RNAppAuthModule.javareads params into aHashMap, whichpermits null values, so
containsKey("state")is true and it callssetState(null), omittingthe parameter. CONTRIBUTING asks that behavior be replicated across both platforms, so this
brings iOS to what Android already does.
Behavior after the change:
Since
nullwas not previously a legal value, this also updatesindex.d.ts(state?: string | nullonBuiltInParameters) and theadditionalParametersdocs, so the opt-out is declaredrather than implied.
One caveat now in the docs: omitting
stateis only safe against providers that do not inventone. If a provider returns a state that was never sent, validation fails from the other
direction. Android behaves the same way, so parity holds.
Deliberately out of scope
nonceon the line above has the same shape. I left it alone because the semantics differ: adocumented opt-out already exists in
useNonce: false, so "null means omit" would add a secondswitch that can contradict the first. Happy to add it if you would rather have the consistency.
logoutforwardsadditionalParametersverbatim toOIDEndSessionRequest, which appends itsown state, so a caller-supplied state is sent twice there. Same class of issue as #974 but on a
different path, so not folded in here.
Steps to verify
There is no iOS test target in this repo, so this is a simulator check against a provider that
does not echo
stateback. Runexamples/demo:authorizewithadditionalParameters: { state: null }. Before this change the flow failswith
State mismatch, expecting <null> but got (null). After it, the authorization URLcarries no
stateparameter and the flow completes.authorizewith nostatekey. A random state is still sent and echoed back, unchangedfrom today.
authorizewithadditionalParameters: { state: 'abc123' }. That exact value is sent.yarn lintpasses.yarn testpasses, though the JS suite has no coverage of this path, so itis not evidence for the fix itself.